{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2024-02-05T13:19:35.328293900Z",
     "start_time": "2024-02-05T13:19:35.215759800Z"
    }
   },
   "outputs": [],
   "source": [
    "import httpx\n",
    "\n",
    "start_end_ret = httpx.post('https://m.suanya.com/restapi/soa2/14666/json/GetTrainStopListV3',\n",
    "                                headers={\n",
    "                                    \"authority\": \"m.suanya.com\",\n",
    "                                    \"accept\": \"*/*\",\n",
    "                                    \"accept-language\": \"zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6\",\n",
    "                                    \"cache-control\": \"max-age=0\",\n",
    "                                    \"content-type\": \"application/x-www-form-urlencoded; charset=UTF-8\",\n",
    "                                    \"if-modified-since\": \"Thu, 01 Jan 1970 00:00:00 GMT\",\n",
    "                                    \"origin\": \"https://www.suanya.com\",\n",
    "                                    \"referer\": \"https://www.suanya.com/\",\n",
    "                                    \"sec-ch-ua\": '\"Not A(Brand\";v=\"99\", \"Microsoft Edge\";v=\"121\", \"Chromium\";v=\"121\"',\n",
    "                                    \"sec-ch-ua-mobile\": \"?0\",\n",
    "                                    \"sec-ch-ua-platform\": '\"Windows\"',\n",
    "                                    \"sec-fetch-dest\": \"empty\",\n",
    "                                    \"sec-fetch-mode\": \"cors\",\n",
    "                                    \"sec-fetch-site\": \"same-site\"\n",
    "                                },\n",
    "                                data={\n",
    "                                    \"TrainName\": \"D2927\",\n",
    "                                    \"DepartStation\": \"赣榆\",\n",
    "                                    \"ArrStation\": \"上海虹桥\",\n",
    "                                    \"DepartureDate\": \"2024-02-06\"\n",
    "                                }\n",
    "                                )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "outputs": [],
   "source": [
    "# 使用orgjson格式化输出 \n",
    "import orjson\n",
    "text = start_end_ret.text\n",
    "data = orjson.loads(text)\n"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-02-05T13:21:32.428260100Z",
     "start_time": "2024-02-05T13:21:32.406810600Z"
    }
   },
   "id": "1b5777335e82ca4d"
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "outputs": [
    {
     "data": {
      "text/plain": "    StationSequence StationName DepartureTime ArrivalTime  StopTimes  \\\n0                 1          威海         15:04       15:04          0   \n1                 2         烟台南         15:29       15:27          2   \n2                 3          莱阳         15:58       15:56          2   \n3                 4         即墨北         16:21       16:19          2   \n4                 5          城阳         16:33       16:31          2   \n5                 6         青岛西         17:10       17:08          2   \n6                 7         日照西         17:46       17:40          6   \n7                 8         岚山西         18:01       17:59          2   \n8                 9          赣榆         18:22       18:20          2   \n9                10         连云港         18:43       18:39          4   \n10               11          灌南         19:11       19:09          2   \n11               12          涟水         19:27       19:24          3   \n12               13         淮安东         19:42       19:39          3   \n13               14          宝应         20:00       19:58          2   \n14               15         扬州东         20:31       20:29          2   \n15               16          丹阳         21:12       20:59         13   \n16               17          常州         21:30       21:28          2   \n17               18          无锡         21:46       21:44          2   \n18               19          苏州         22:04       22:02          2   \n19               20         昆山南         22:18       22:16          2   \n20               21        上海虹桥         22:38       22:38          0   \n\n    DistanceFromStart  \n0                   0  \n1                   0  \n2                   0  \n3                   0  \n4                   0  \n5                   0  \n6                   0  \n7                   0  \n8                   0  \n9                   0  \n10                  0  \n11                  0  \n12                  0  \n13                  0  \n14                  0  \n15                  0  \n16                  0  \n17                  0  \n18                  0  \n19                  0  \n20                  0  ",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>StationSequence</th>\n      <th>StationName</th>\n      <th>DepartureTime</th>\n      <th>ArrivalTime</th>\n      <th>StopTimes</th>\n      <th>DistanceFromStart</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>1</td>\n      <td>威海</td>\n      <td>15:04</td>\n      <td>15:04</td>\n      <td>0</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>2</td>\n      <td>烟台南</td>\n      <td>15:29</td>\n      <td>15:27</td>\n      <td>2</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>3</td>\n      <td>莱阳</td>\n      <td>15:58</td>\n      <td>15:56</td>\n      <td>2</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>4</td>\n      <td>即墨北</td>\n      <td>16:21</td>\n      <td>16:19</td>\n      <td>2</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>5</td>\n      <td>城阳</td>\n      <td>16:33</td>\n      <td>16:31</td>\n      <td>2</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>5</th>\n      <td>6</td>\n      <td>青岛西</td>\n      <td>17:10</td>\n      <td>17:08</td>\n      <td>2</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>6</th>\n      <td>7</td>\n      <td>日照西</td>\n      <td>17:46</td>\n      <td>17:40</td>\n      <td>6</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>7</th>\n      <td>8</td>\n      <td>岚山西</td>\n      <td>18:01</td>\n      <td>17:59</td>\n      <td>2</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>8</th>\n      <td>9</td>\n      <td>赣榆</td>\n      <td>18:22</td>\n      <td>18:20</td>\n      <td>2</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>9</th>\n      <td>10</td>\n      <td>连云港</td>\n      <td>18:43</td>\n      <td>18:39</td>\n      <td>4</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>10</th>\n      <td>11</td>\n      <td>灌南</td>\n      <td>19:11</td>\n      <td>19:09</td>\n      <td>2</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>11</th>\n      <td>12</td>\n      <td>涟水</td>\n      <td>19:27</td>\n      <td>19:24</td>\n      <td>3</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>12</th>\n      <td>13</td>\n      <td>淮安东</td>\n      <td>19:42</td>\n      <td>19:39</td>\n      <td>3</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>13</th>\n      <td>14</td>\n      <td>宝应</td>\n      <td>20:00</td>\n      <td>19:58</td>\n      <td>2</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>14</th>\n      <td>15</td>\n      <td>扬州东</td>\n      <td>20:31</td>\n      <td>20:29</td>\n      <td>2</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>15</th>\n      <td>16</td>\n      <td>丹阳</td>\n      <td>21:12</td>\n      <td>20:59</td>\n      <td>13</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>16</th>\n      <td>17</td>\n      <td>常州</td>\n      <td>21:30</td>\n      <td>21:28</td>\n      <td>2</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>17</th>\n      <td>18</td>\n      <td>无锡</td>\n      <td>21:46</td>\n      <td>21:44</td>\n      <td>2</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>18</th>\n      <td>19</td>\n      <td>苏州</td>\n      <td>22:04</td>\n      <td>22:02</td>\n      <td>2</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>19</th>\n      <td>20</td>\n      <td>昆山南</td>\n      <td>22:18</td>\n      <td>22:16</td>\n      <td>2</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>20</th>\n      <td>21</td>\n      <td>上海虹桥</td>\n      <td>22:38</td>\n      <td>22:38</td>\n      <td>0</td>\n      <td>0</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train_stop_list = data[\"TrainStopList\"]\n",
    "# 使用pandas格式化输出\n",
    "import pandas as pd\n",
    "df = pd.DataFrame(train_stop_list)\n",
    "df\n"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-02-05T13:22:30.442585600Z",
     "start_time": "2024-02-05T13:22:30.428564Z"
    }
   },
   "id": "dee757235de676d3"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false
   },
   "id": "689019b94480ab03"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
